Component({
  properties: {
    address: Object,
    defaultAddressId: Number,
    selectedAddressId: Number,
    index: Number,
  },

  methods: {
    // 选中地址
    selectAddress(e) {
      const { id } = e.currentTarget.dataset;

      // 通知父组件选中地址
      this.triggerEvent('address-selected', { id });
    },

    // 设置为默认地址
    setDefault(e) {
      const { id } = e.currentTarget.dataset;

      // 通知父组件设置默认地址
      this.triggerEvent('set-default', { id });
    },
    // 执行删除、复制、修改操作
    handleAction(e) {
      const action = e.currentTarget.dataset.action;
      const { index } = this.properties;

      // 通知父组件执行对应操作
      this.triggerEvent('address-action', { action, index });
    },
  },
});
